<template>
  <div class="app-container">
    <el-dialog
      :title="dialogtitle"
      :visible.sync="dialogVisible"
      width="98%"
      top="20px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      append-to-body
    >
      <detail :item="item" :timestamp="timestamp" />
    </el-dialog>

    <div class="filter-container">
      <el-select v-model="listQuery.org" placeholder="请选择检测机构" clearable style="margin-left: 10px;width: 300px" class="filter-item">
        <el-option label="全部" value="" />
        <el-option v-for="(it,index) in checkerList" :key="index" :label="it.organizationname" :value="it.organizationname" />
      </el-select>
      <el-input v-model="listQuery.vin" placeholder="车辆VIN" style="width: 200px;margin-left: 10px;" class="filter-item" />
      <el-input v-model="listQuery.model" placeholder="车辆型号" style="width: 200px;margin-left: 10px;" class="filter-item" />
      <el-input v-model="listQuery.firm" placeholder="生产企业" style="width: 200px;margin-left: 10px;" class="filter-item" />
      试验创建日期<el-date-picker v-model="listQuery.startDate" type="daterange" placeholder="请选择日期" style="width: 300px;margin-left: 10px;" value-format="yyyy-MM-dd" class="filter-item" />
      <el-button class="filter-item" type="primary" icon="el-icon-search" style="margin-left: 10px;" @click="getList">
        搜索
      </el-button>
    </div>
    <el-table
      v-if="showTable"
      ref="multipleTable"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >

      <el-table-column prop="org" min-width="300px" label="检测机构" show-overflow-tooltip />
      <el-table-column prop="vin" label="车辆VIN" width="200" show-overflow-tooltip />
      <el-table-column prop="model" label="车辆型号" width="180" show-overflow-tooltip />
      <el-table-column prop="firm" label="生产企业" width="300" show-overflow-tooltip />
      <el-table-column prop="title" label="车辆名称" width="150" show-overflow-tooltip />
      <el-table-column prop="type" label="车辆类型" width="150" show-overflow-tooltip />
      <el-table-column prop="start_date" label="创建时间" width="160" show-overflow-tooltip />
      <el-table-column prop="status" label="试验状态" width="90" show-overflow-tooltip />
      <el-table-column align="center" label="操作" width="120">
        <template slot-scope="scope">
          <el-button size="small" @click="detail(scope.row)">
            查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import detail from './components/ArticleDetail'

export default {
  name: 'ArticleList',
  components: { detail },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      showTable: false,
      checkerList: [],
      item: {},
      dialogtitle: '新增',
      dialogVisible: false,
      timestamp: false,
      list: [],
      listLoading: true,
      listQuery: {
        org: '',
        vin: '',
        model: '',
        firm: '',
        startDate: []
      }
    }
  },
  mounted() {
    this.getCheckerList()
  },
  methods: {
    detail(item) {
      this.item = item
      this.dialogtitle = '查看'
      this.dialogVisible = true
      this.timestamp = new Date().getTime()
    },
    getList() {
      this.showTable = true
      this.listLoading = true
      const para = {
        'vin': this.listQuery.vin,
        'firm': this.listQuery.firm,
        'model': this.listQuery.model,
        'org': this.listQuery.org,
        'startDate': this.listQuery.startDate ? this.listQuery.startDate[0] : null,
        'finishDate': this.listQuery.startDate ? this.listQuery.startDate[1] : null
      }
      this.$http
        .post('/api/webservice/videoList', para)
        .then(response => {
          this.listLoading = false
          if (response.data.success === true) {
            this.list = response.data.result
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.listLoading = false
        })
    },
    getCheckerList() {
      this.listLoading = true
      this.$http
        .get('/api/webservice/getCheckerList')
        .then(response => {
          this.listLoading = false
          if (response.data.success === true) {
            this.checkerList = response.data.result
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.listLoading = false
        })
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
